package com.bjtech.web.action.management;

import java.util.List;

import com.bjtech.dao.BaseRoomInfoDao;
import com.bjtech.dao.LoginUserInfoDao;
import com.bjtech.dao.ShareSinkResultDao;
import com.bjtech.dao.ShareUserResultDao;
import com.bjtech.domain.LoginUserInfo;
import com.bjtech.domain.ShareAreaResult;
import com.bjtech.domain.ShareSinkResult;
import com.bjtech.domain.ShareUserResult;
import com.bjtech.domain.User;
import com.bjtech.domain.query.ShareSinkResultQuerySpec;
import com.bjtech.domain.query.ShareUserResultQuerySpec;
import com.bjtech.web.action.LyheatBaseAction;

public class ShareUserResultAction extends LyheatBaseAction {

	private static final long serialVersionUID = 1L;
	private ShareUserResultDao shareUserResultDao;
	private ShareUserResultQuerySpec selectBean;
	
	private List shareSinkResultList;
	private List shareSinkResultListNew;
	private ShareSinkResultDao shareSinkResultDao;
	private LoginUserInfoDao loginUserInfoDao;
	
	private BaseRoomInfoDao baseRoomInfoDao;
	
	public void prepare() throws Exception {

	}
	
	public ShareUserResultAction() throws Exception{
		model = new ShareUserResult();
		selectBean = new ShareUserResultQuerySpec();
	}
	
	public void setShareUserResultDao(ShareUserResultDao shareUserResultDao) {
		this.shareUserResultDao = shareUserResultDao;
	}

	public String execute(){
		return this.list();
	}
	
	public String list(){
		User user = this.getUser();
		if(user.getUserRole()!=null&&user.getUserId()!=null){
			if(user.getUserRole().intValue()==7){
				LoginUserInfo loginUser = loginUserInfoDao.selectEntity(new LoginUserInfo(), user.getUserId());
				if(loginUser.getRoom_id()!=null){
					selectBean.setRoom_id(loginUser.getRoom_id());
				}else{
					selectBean.setRoom_id(0l);
				}
			}
			selectBean.queryParamString();
			list = this.shareUserResultDao.selectEntityPaginatedList(new ShareUserResult(),selectBean);
		}
		return "list";
	}
	
	public String add(){
		return "edit";
	}
	
	public String save(){
		ShareUserResult entity = (ShareUserResult)model;
		if(entity.getId()==null){
			shareUserResultDao.insertEntity(entity);
		}else{
			shareUserResultDao.updateEntity(entity);
		}
		return "success";
	}
	
	public String edit(){
		model = this.shareUserResultDao.selectEntity(new ShareUserResult(),id);
		return "edit";
	}

	public String view(){
		model = this.shareUserResultDao.selectEntity(new ShareUserResult(),id);
		ShareSinkResultQuerySpec spec =new ShareSinkResultQuerySpec();
		spec.setUser_result_id(id);
		spec.queryParamString();
		shareSinkResultList = shareSinkResultDao.selectEntityList(new ShareSinkResult(), spec);
	//	shareSinkResultListNew = shareSinkResultDao.shareSinkResultListNew(entity, sb)
		return "view";
	}
	
	public String delete(){
		model = this.shareUserResultDao.deleteEntity(new ShareUserResult(),id);
		return "success";
	}
	
	public ShareUserResultQuerySpec getSelectBean() {
		return selectBean;
	}

	public void setSelectBean(ShareUserResultQuerySpec selectBean) {
		this.selectBean = selectBean;
	}

	public List getShareSinkResultList() {
		return shareSinkResultList;
	}

	public void setShareSinkResultList(List shareSinkResultList) {
		this.shareSinkResultList = shareSinkResultList;
	}

	public ShareSinkResultDao getShareSinkResultDao() {
		return shareSinkResultDao;
	}

	public void setShareSinkResultDao(ShareSinkResultDao shareSinkResultDao) {
		this.shareSinkResultDao = shareSinkResultDao;
	}

	public ShareUserResultDao getShareUserResultDao() {
		return shareUserResultDao;
	}

	public LoginUserInfoDao getLoginUserInfoDao() {
		return loginUserInfoDao;
	}

	public void setLoginUserInfoDao(LoginUserInfoDao loginUserInfoDao) {
		this.loginUserInfoDao = loginUserInfoDao;
	}

	public BaseRoomInfoDao getBaseRoomInfoDao() {
		return baseRoomInfoDao;
	}

	public void setBaseRoomInfoDao(BaseRoomInfoDao baseRoomInfoDao) {
		this.baseRoomInfoDao = baseRoomInfoDao;
	}

	public List getShareSinkResultListNew() {
		return shareSinkResultListNew;
	}

	public void setShareSinkResultListNew(List shareSinkResultListNew) {
		this.shareSinkResultListNew = shareSinkResultListNew;
	}
}
